package com.qili.controller;

import com.qili.core.utils.DictTypes;
import com.qili.core.utils.DictUtil;
import com.qili.entity.base.BaseCompanyOwner;
import com.qili.entity.base.BaseDict;
import com.qili.entity.jc.dto.JcProjectDTO;
import com.qili.entity.supervisor.dto.SupervisorProjectDTO;
import com.qili.entity.sys.SysRegion;
import com.qili.entity.sys.dto.SysUserDTO;
import com.qili.entity.zx.dto.ZxProjectDTO;
import com.qili.mapper.jc.JcProjectMapper;
import com.qili.mapper.supervisor.SupervisorProjectMapper;
import com.qili.mapper.sys.SysUserMapper;
import com.qili.mapper.zx.ZxProjectMapper;
import com.qili.service.base.BaseCompanyOwnerService;
import com.qili.service.base.BaseDictService;
import com.qili.service.sys.SysRegionService;
import com.qili.util.DateUtil;
import com.qili.util.ExcelExportUtil;
import com.qili.util.ReType;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author zhangxiaopeng
 * @date 2021-05-10
 */
@RequestMapping("/search/analysis")
@Controller
public class AnalysisController {
    @Autowired
    BaseCompanyOwnerService baseCompanyOwnerService;
    @Autowired
    SysRegionService sysRegionService;
    @Autowired
    SupervisorProjectMapper supervisorProjectMapper;
    @Autowired
    ZxProjectMapper zxProjectMapper;
    @Autowired
    JcProjectMapper jcProjectMapper;
    @Autowired
    SysUserMapper sysUserMapper;
    @Autowired
    BaseDictService baseDictService;
    /**
     * @param request
     * @Author:zhangxiaopeng
     * @Description: 项目签单页面
     * @Date:13:38 2021/4/6
     */
    @GetMapping(value = "signing")
    @RequiresPermissions("zn:tj:qd")
    public String index(HttpServletRequest request, Model model) {
        /*项目类型*/
        model.addAttribute("xmlx", base(DictTypes.YW_TYPE));
        /*行业*/
        model.addAttribute("hy", base(DictTypes.INDUSTRY));
        /*项目归属*/
        List<BaseCompanyOwner> AlstCompany = baseCompanyOwnerService.selectAll();
        model.addAttribute("xmgs",AlstCompany);
        // 省
        List<SysRegion> provincelist = sysRegionService.selectListByLevelId("1");
        model.addAttribute("ssdd",provincelist);
        /*时间段*/
        model.addAttribute("sjd", base(DictTypes.SJD001));
        return "analysis/signing";
    }
    /**
     * @param request
     * @Author:zhangxiaopeng
     * @Description: 项目进度页面
     * @Date:13:38 2021/4/6
     */
    @GetMapping(value = "progress")
    @RequiresPermissions("zn:tj:jd")
    public String progress(HttpServletRequest request, Model model) {
        /*项目类型*/
        model.addAttribute("xmlx", base(DictTypes.YW_TYPE));
        /*行业*/
        model.addAttribute("hy", base(DictTypes.INDUSTRY));
        /*项目归属*/
        List<BaseCompanyOwner> AlstCompany = baseCompanyOwnerService.selectAll();
        model.addAttribute("xmgs",AlstCompany);
        // 省
        List<SysRegion> provincelist = sysRegionService.selectListByLevelId("1");
        model.addAttribute("ssdd",provincelist);
        /*时间段*/
        model.addAttribute("sjd", base(DictTypes.SJD001));
        return "analysis/progress";
    }
    /**
     * @param request
     * @Author:zhangxiaopeng
     * @Description: 人员情况页面
     * @Date:13:38 2021/4/6
     */
    @GetMapping(value = "situation")
    @RequiresPermissions("zn:tj:ry")
    public String situation(HttpServletRequest request, Model model) {
        /*项目归属*/
        List<BaseCompanyOwner> AlstCompany = baseCompanyOwnerService.selectAll();
        model.addAttribute("xmgs",AlstCompany);
        // 省
        List<SysRegion> provincelist = sysRegionService.selectListByLevelId("1");
        model.addAttribute("ssdd",provincelist);
        return "analysis/situation";
    }

    /**
     * @param request
     * @Author:zhangxiaopeng
     * @Description: 项目分布页面
     * @Date:13:38 2021/4/6
     */
    @GetMapping(value = "distribution")
    @RequiresPermissions("zn:tj:fb")
    public String distribution(HttpServletRequest request, Model model) {
        /*项目类型*/
        model.addAttribute("xmlx", base(DictTypes.YW_TYPE));
        /*项目状态*/
        model.addAttribute("xmzt", base(DictTypes.UNIT_NATURE));
        /*项目归属*/
        List<BaseCompanyOwner> AlstCompany = baseCompanyOwnerService.selectAll();
        model.addAttribute("xmgs",AlstCompany);
        /*时间段*/
        model.addAttribute("sjd", base(DictTypes.SJD001));
        return "analysis/distribution";
    }

    /**
     * @param request
     * @Author:zhangxiaopeng
     * @Description: 公司合同额页面
     * @Date:13:38 2021/4/6
     */
    @GetMapping(value = "company/amount")
    @RequiresPermissions("zn:tj:gshte")
    public String companyAmount(HttpServletRequest request, Model model) {
        /*项目类型*/
        model.addAttribute("xmlx", base(DictTypes.YW_TYPE));
        /*行业*/
        model.addAttribute("hy", base(DictTypes.INDUSTRY));
        /*项目归属*/
        List<BaseCompanyOwner> AlstCompany = baseCompanyOwnerService.selectAll();
        model.addAttribute("xmgs",AlstCompany);
        // 省
        List<SysRegion> provincelist = sysRegionService.selectListByLevelId("1");
        model.addAttribute("ssdd",provincelist);
        /*项目状态*/
        model.addAttribute("xmzt", base(DictTypes.UNIT_NATURE));
        /*时间段*/
        model.addAttribute("sjd", base(DictTypes.SJD001));
        return "analysis/companyAmount";
    }

    /**
     * @param request
     * @Author:zhangxiaopeng
     * @Description: 总部合同额页面
     * @Date:13:38 2021/4/6
     */
    @GetMapping(value = "headquarters/amount")
    @RequiresPermissions("zn:tj:zbhte")
    public String headquartersAmount(HttpServletRequest request, Model model) {
        /*项目类型*/
        model.addAttribute("xmlx", base(DictTypes.YW_TYPE));
        /*行业*/
        model.addAttribute("hy", base(DictTypes.INDUSTRY));
        // 省
        List<SysRegion> provincelist = sysRegionService.selectListByLevelId("1");
        model.addAttribute("ssdd",provincelist);
        /*项目状态*/
        model.addAttribute("xmzt", base(DictTypes.UNIT_NATURE));
        /*时间段*/
        model.addAttribute("sjd", base(DictTypes.SJD001));
        return "analysis/headquartersAmount";
    }

    /**
     * @param request
     * @Author:zhangxiaopeng
     * @Description: 合同额对比页面
     * @Date:13:38 2021/4/6
     */
    @GetMapping(value = "amount/contrast")
    @RequiresPermissions("zn:tj:htedb")
    public String amountContrast(HttpServletRequest request, Model model) {
        /*项目类型*/
        model.addAttribute("xmlx", base(DictTypes.YW_TYPE));
        /*行业*/
        model.addAttribute("hy", base(DictTypes.INDUSTRY));
        /*项目归属*/
        List<BaseCompanyOwner> AlstCompany = baseCompanyOwnerService.selectAll();
        model.addAttribute("xmgs",AlstCompany);
        // 省
        List<SysRegion> provincelist = sysRegionService.selectListByLevelId("1");
        model.addAttribute("ssdd",provincelist);
        /*项目状态*/
        model.addAttribute("xmzt", base(DictTypes.UNIT_NATURE));
        /*时间段*/
        model.addAttribute("sjd", base(DictTypes.SJD001));
        return "analysis/amountContrast";
    }

    //项目签单模块导出Excel
    @RequestMapping(value="exportExcel")
    public void exportExcelQd(HttpServletRequest request, HttpServletResponse response) throws IOException, ParseException {
        String  fileName="项目签单统计表"+DateUtil.getCurrentDateNoSpliter();
        HashMap map=new HashMap();
        Map map1=new HashMap();
        //类型
        List<String> name=list(request.getParameter("name"));
        map1.put("names",name);
        //数量
        List<String> number=list(request.getParameter("number"));
        map1.put("numbers",number);
        List<Integer> serial=new ArrayList<>();
        for(int i=0;i<name.size();i++){
            serial.add(i+1);
        }
        //序号
        map1.put("serials",serial);
        List<Map> ss=new ArrayList<>();
        ss.add(map1);
        map.put("records",ss);
        String content="";
        //时间段
        String startTime=request.getParameter("startTime");
        String endTime=request.getParameter("endTime");
        String start ="";String end ="";
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
//            Date date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(startTime);
//            Date date1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(endTime);
            start=startTime;
            end=start;
        }

        //项目归属
        String company=request.getParameter("company");
        StringJoiner sj = new StringJoiner("、");
        String xmgs="";
        if(StringUtils.isNotBlank(company)){
            String [] arr=company.split(",");
            BaseCompanyOwner baseCompany = new BaseCompanyOwner();
            for(int i=0;i<arr.length;i++){
                baseCompany= baseCompanyOwnerService.selectByPrimaryKey(arr[i]);
                sj.add(baseCompany.getBcName());
            }
            xmgs=sj.toString();
        }

        //项目实施地点  省   市
        String province=request.getParameter("province");
        String sheng="";
        SysRegion region=new SysRegion();
        if(StringUtils.isNotBlank(province)) {
            region.setCode(province);
            SysRegion sysRegion = sysRegionService.selectOne(region);
            sheng=sysRegion.getName();
        }
        String city=request.getParameter("city");
        String shi="";
        if(StringUtils.isNotBlank(city)) {
            region.setCode(city);
            SysRegion sysRegions = sysRegionService.selectOne(region);
            shi=sysRegions.getName();
        }
        //业务类型
        String projectType=request.getParameter("projectType");
        String ywlx="";
        if(StringUtils.isNotBlank(projectType)){
            StringJoiner joiner = new StringJoiner(",");
            String [] arr=projectType.split(",");
            BaseDict base=new BaseDict();
            for(int i=0;i<arr.length;i++){
                base=baseDict("BT001",arr[i]);
                joiner.add(base.getBadtName());
            }
            ywlx=joiner.toString();
        }
        //表头内容
        if(StringUtils.isBlank(start)||StringUtils.isBlank(xmgs)||StringUtils.isBlank(sheng)) {
            content = "项目签单统计表";
        }else{
            content = start+"至" + end + xmgs + "在" + sheng + shi + "的" + ywlx + "的项目签单统计表";
        }
//        System.err.println(content);
        map.put("name",content);
        try {
            ExcelExportUtil.exportExcel(response,map,fileName,"78001");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //项目进度模块导出Excel
    @RequestMapping(value="projectPlan")
    public void projectPlan(HttpServletRequest request, HttpServletResponse response) throws IOException, ParseException {
        String  fileName="项目进度统计表"+DateUtil.getCurrentDateNoSpliter();
        HashMap map=new HashMap();
        List<Map> listMap=selectPlan(request);
        map.put("records",listMap);
        String content="";
        //时间段
        String startTime=request.getParameter("startTime");
        String endTime=request.getParameter("endTime");
        String start ="";String end ="";
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
//            Date date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(startTime);
//            Date date1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(endTime);
            start=startTime;
            end=start;
        }

        //项目归属
        String company=request.getParameter("company");
        StringJoiner sj = new StringJoiner("、");
        String xmgs="";
        if(StringUtils.isNotBlank(company)){
            String [] arr=company.split(",");
            BaseCompanyOwner baseCompany = new BaseCompanyOwner();
            for(int i=0;i<arr.length;i++){
                baseCompany= baseCompanyOwnerService.selectByPrimaryKey(arr[i]);
                sj.add(baseCompany.getBcName());
            }
            xmgs=sj.toString();
        }

        //项目实施地点  省   市
        String province=request.getParameter("province");
        String sheng="";
        SysRegion region=new SysRegion();
        if(StringUtils.isNotBlank(province)) {
            region.setCode(province);
            SysRegion sysRegion = sysRegionService.selectOne(region);
            sheng=sysRegion.getName();
        }
        String city=request.getParameter("city");
        String shi="";
        if(StringUtils.isNotBlank(city)) {
            region.setCode(city);
            SysRegion sysRegions = sysRegionService.selectOne(region);
            shi=sysRegions.getName();
        }
        //业务类型
        String projectType=request.getParameter("projectType");
        String ywlx="";
        if(StringUtils.isNotBlank(projectType)){
            StringJoiner joiner = new StringJoiner(",");
            String [] arr=projectType.split(",");
            BaseDict base=new BaseDict();
            for(int i=0;i<arr.length;i++){
                base=baseDict("BT001",arr[i]);
                joiner.add(base.getBadtName());
            }
            ywlx=joiner.toString();
        }
        //项目个数
        String gs=request.getParameter("projectNum");
        //行业
        String industry=request.getParameter("industry");
        String hangye="";
        if(StringUtils.isNotBlank(industry)){
            StringJoiner joiner = new StringJoiner("、");
            String [] arr=industry.split(",");
            BaseDict base=new BaseDict();
            for(int i=0;i<arr.length;i++){
                base=baseDict("HY001",arr[i]);
                joiner.add(base.getBadtName());
            }
            hangye=joiner.toString();
        }
        //表头内容
        if(StringUtils.isBlank(start)||StringUtils.isBlank(xmgs)||StringUtils.isBlank(sheng)) {
            content = "进度统计表";
        }else{
            content = start+"至" + end + xmgs + "在" + sheng + shi+ hangye+ "行业的最新"+gs+"个"+ ywlx + "项目的进度统计表";
        }
//        System.err.println(content);
        map.put("name",content);
        try {
            ExcelExportUtil.exportExcel(response,map,fileName,"78005");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //数据查询
    public List<Map> selectPlan(HttpServletRequest request){
        List<Map> listMap=new ArrayList<>();

        Map map =new HashMap();
        //时间段
        String startTime=request.getParameter("startTime");
        String endTime=request.getParameter("endTime");
        //省份
        String province=request.getParameter("province");
        //市
        String city=request.getParameter("city");
        //业务类型
        String projectType=request.getParameter("projectType");
        //项目归属
        String company=request.getParameter("company");
        //行业
        String industry=request.getParameter("industry");
        //项目个数
        String projectNum=request.getParameter("projectNum");
//        System.err.println("时间段:"+times+"省份:"+province+"市："+city+"业务类型："+projectType+"项目归属："+company+"行业:"+industry);
        map.put("province",province);
        map.put("city",city);
        map.put("company",list(company));
        map.put("industry",list(industry));
        map.put("projectNum",Integer.parseInt(projectNum));
        //时间段
        map.put("start",startTime);
        map.put("end",endTime);
        if("001".equals(projectType)){
            List<SupervisorProjectDTO> list= supervisorProjectMapper.selectSupervisorList(map);
            if(list!=null && list.size()>0){
                for(int i=0;i<list.size();i++) {
                    Map re = new HashMap();
                    re.put("name",list.get(i).getProjectName());
                    re.put("num",list.get(i).getProgress()+"%");
                    re.put("number",i+1);
                    listMap.add(re);
                }
            }
        }
        return listMap;
    }

    //公司合同额模块导出Excel
    @RequestMapping(value="companyExcel")
    public void companyExcelQd(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String  fileName="公司合同额统计表"+DateUtil.getCurrentDateNoSpliter();
        HashMap map=new HashMap();
        List<Map> ss=selectExce(request);
        map.put("records",ss);
        String content="";
        //导出时的月份表头
        String startTime=request.getParameter("startTime");
        String endTime=request.getParameter("endTime");
        map.put("start",startTime);
        map.put("end",endTime);

        List<String> timeList=getMonthBetween(startTime,endTime);
        map.put("times",timeList);
        //时间段
        String start ="";String end ="";
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
//            Date date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(startTime);
//            Date date1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(endTime);
//            start=new SimpleDateFormat("yyyy-MM-dd").format(date);
//            end=new SimpleDateFormat("yyyy-MM-dd").format(date1);
            start=startTime;
            end=endTime;
        }
        //项目归属
        String company=request.getParameter("company");
        StringJoiner sj = new StringJoiner("、");
        String xmgs="";
        if(StringUtils.isNotBlank(company)){
            String [] arr=company.split(",");
            BaseCompanyOwner baseCompany = new BaseCompanyOwner();
            for(int i=0;i<arr.length;i++){
                baseCompany= baseCompanyOwnerService.selectByPrimaryKey(arr[i]);
                sj.add(baseCompany.getBcName());
            }
            xmgs=sj.toString();
        }

        //项目实施地点  省   市
        String province=request.getParameter("province");
        String sheng="";
        SysRegion region=new SysRegion();
        if(StringUtils.isNotBlank(province)) {
            region.setCode(province);
            SysRegion sysRegion = sysRegionService.selectOne(region);
            sheng=sysRegion.getName();
        }
        String city=request.getParameter("city");
        String shi="";
        if(StringUtils.isNotBlank(city)) {
            region.setCode(city);
            SysRegion sysRegions = sysRegionService.selectOne(region);
            shi=sysRegions.getName();
        }
        //业务类型
        String projectType=request.getParameter("projectType");
        String ywlx="";
        if(StringUtils.isNotBlank(projectType)){
            StringJoiner joiner = new StringJoiner(",");
            String [] arr=projectType.split(",");
            BaseDict base=new BaseDict();
            for(int i=0;i<arr.length;i++){
                base=baseDict("BT001",arr[i]);
                joiner.add(base.getBadtName());
            }
            ywlx=joiner.toString();
        }
        //行业
        String industry=request.getParameter("industry");
        String hangye="";
        if(StringUtils.isNotBlank(industry)){
            StringJoiner joiner = new StringJoiner("、");
            String [] arr=industry.split(",");
            BaseDict base=new BaseDict();
            for(int i=0;i<arr.length;i++){
                base=baseDict("HY001",arr[i]);
                joiner.add(base.getBadtName());
            }
            hangye=joiner.toString();
        }
        //表头内容
        if(StringUtils.isBlank(start)||StringUtils.isBlank(xmgs)||StringUtils.isBlank(sheng)||StringUtils.isBlank(shi)) {
            content ="公司合同额统计表";
        }else{
            content = start+"至" + end + xmgs + "在" + sheng + shi+hangye + "行业的" + ywlx + "的公司合同额统计表";
        }
//        System.err.println(content);
        map.put("name",content);
        try {
            ExcelExportUtil.exportExcel(response,map,fileName,"78002");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //公司合同额模块导出 数据处理
    public List<Map> selectExce(HttpServletRequest request){
        List<Map> maps=new ArrayList<>();
        Map map2=new HashMap();
        //时间段
        String startTime=request.getParameter("startTime");
        String endTime=request.getParameter("endTime");

        //省份
        String province=request.getParameter("province");
        //市
        String city=request.getParameter("city");
        //业务类型
        String projectType=request.getParameter("projectType");
        //项目归属
        String company=request.getParameter("company");
        //行业
        String industry=request.getParameter("industry");
        //项目状态
        String status=request.getParameter("status");
        map2.put("province",province);
        map2.put("city",city);
        map2.put("company",list(company));
        map2.put("industry",list(industry));
        map2.put("status",status);
        //时间段
        map2.put("start",startTime);
        map2.put("end",endTime);
        String[] arr = projectType.split(",");
        for (int i = 0; i < arr.length; i++) {
            BaseDict base=baseDict("BT001",arr[i]);
            Map<String,Object> map = new HashMap<>();
            if(base!=null&&!"".equals(base)){
                if ("001".equals(arr[i])) {
                    if(StringUtils.isNotBlank(base.getBadtName())){
                        map.put("type",base.getBadtName());
                    }
                    List<SupervisorProjectDTO> listJl=supervisorProjectMapper.selectAmount(map2);
                    for(SupervisorProjectDTO jl:listJl){
                        map.put(jl.getContractSignTime(),jl.getHtMoney());
                    }

                }
                if("002".equals(arr[i])){
                    map.put("type",base.getBadtName());
                }
                if("003".equals(arr[i])){
                    map.put("type",base.getBadtName());
                }
                if("100".equals(arr[i])){
                    map.put("type",base.getBadtName());
                }
            }
            maps.add(map);
        }

        return maps;
    }

    //总部合同额模块导出Excel
    @RequestMapping(value="headquartersExcel")
    public void headquartersExcelQd(HttpServletRequest request, HttpServletResponse response) throws IOException, ParseException {
        String  fileName="总部合同额统计表"+DateUtil.getCurrentDateNoSpliter();
        HashMap map=new HashMap();
        Map map1=new HashMap();
        //类型
        List<String> name=list(request.getParameter("name"));
        map1.put("names",name);
        //数量
        List<String> number=list(request.getParameter("number"));
        map1.put("numbers",number);
        List<Integer> serial=new ArrayList<>();
        for(int i=0;i<name.size();i++){
            serial.add(i+1);
        }
        //序号
        map1.put("serials",serial);
        List<Map> ss=new ArrayList<>();
        ss.add(map1);
        map.put("records",ss);
        String content="";
        //时间段
        String startTime=request.getParameter("startTime");
        String endTime=request.getParameter("endTime");
        String start ="";String end ="";
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
//            Date date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(startTime);
//            Date date1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(endTime);
            start=startTime;
            end=endTime;
        }

        //项目实施地点  省   市
        String province=request.getParameter("province");
        String sheng="";
        SysRegion region=new SysRegion();
        if(StringUtils.isNotBlank(province)) {
            region.setCode(province);
            SysRegion sysRegion = sysRegionService.selectOne(region);
            sheng=sysRegion.getName();
        }
        String city=request.getParameter("city");
        String shi="";
        if(StringUtils.isNotBlank(city)) {
            region.setCode(city);
            SysRegion sysRegions = sysRegionService.selectOne(region);
            shi=sysRegions.getName();
        }
        //业务类型
        String projectType=request.getParameter("projectType");
        String ywlx="";
        if(StringUtils.isNotBlank(projectType)){
            StringJoiner joiner = new StringJoiner(",");
            String [] arr=projectType.split(",");
            BaseDict base=new BaseDict();
            for(int i=0;i<arr.length;i++){
                base=baseDict("BT001",arr[i]);
                joiner.add(base.getBadtName());
            }
            ywlx=joiner.toString();
        }
        //行业
        String industry=request.getParameter("industry");
        String hangye="";
        if(StringUtils.isNotBlank(industry)){
            StringJoiner joiner = new StringJoiner("、");
            String [] arr=industry.split(",");
            BaseDict base=new BaseDict();
            for(int i=0;i<arr.length;i++){
                base=baseDict("HY001",arr[i]);
                joiner.add(base.getBadtName());
            }
            hangye=joiner.toString();
        }
        //表头内容
        if(StringUtils.isBlank(start)||StringUtils.isBlank(sheng)||StringUtils.isBlank(shi)||StringUtils.isBlank(ywlx)) {
            content ="总部合同额统计表";
        }else{
            content = start+"至" + end +"公司总部在" + sheng + shi+hangye + "行业的" + ywlx + "的总部合同额统计表";
        }

//        System.err.println(content);
        map.put("name",content);
        try {
            ExcelExportUtil.exportExcel(response,map,fileName,"78003");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //合同额对比模块导出Excel
    @RequestMapping(value="contrastExcel")
    public void contrastExcelQd(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String  fileName="合同额对比统计表"+DateUtil.getCurrentDateNoSpliter();
        HashMap map=new HashMap();
        List<Map> ss=selectContrastExce(request);
        map.put("records",ss);
        String content="";
        //业务类型表头
        String projectType=request.getParameter("projectType");
        String[] arrs = projectType.split(",");
        BaseDict bases=new BaseDict();
        List<String> typeName=new ArrayList<>();
        for(int i=0;i<arrs.length;i++){
            bases=baseDict("BT001",arrs[i]);
            typeName.add(bases.getBadtName());
        }
        map.put("typeName",typeName);
        //时间段
        String startTime=request.getParameter("startTime");
        String endTime=request.getParameter("endTime");
        String start ="";String end ="";
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
//            Date date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(startTime);
//            Date date1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(endTime);
            start=startTime;
            end=endTime;
        }
        //项目归属
        String company=request.getParameter("company");
        StringJoiner sj = new StringJoiner("、");
        String xmgs="";
        if(StringUtils.isNotBlank(company)){
            String [] arr=company.split(",");
            BaseCompanyOwner baseCompany = new BaseCompanyOwner();
            for(int i=0;i<arr.length;i++){
                baseCompany= baseCompanyOwnerService.selectByPrimaryKey(arr[i]);
                sj.add(baseCompany.getBcName());
            }
            xmgs=sj.toString();
        }

        //项目实施地点  省   市
        String province=request.getParameter("province");
        String sheng="";
        SysRegion region=new SysRegion();
        if(StringUtils.isNotBlank(province)) {
            region.setCode(province);
            SysRegion sysRegion = sysRegionService.selectOne(region);
            sheng=sysRegion.getName();
        }
        String city=request.getParameter("city");
        String shi="";
        if(StringUtils.isNotBlank(city)) {
            region.setCode(city);
            SysRegion sysRegions = sysRegionService.selectOne(region);
            shi=sysRegions.getName();
        }
        //业务类型
        String ywlx="";
        if(StringUtils.isNotBlank(projectType)){
            StringJoiner joiner = new StringJoiner(",");
            String [] arr=projectType.split(",");
            BaseDict base=new BaseDict();
            for(int i=0;i<arr.length;i++){
                base=baseDict("BT001",arr[i]);
                joiner.add(base.getBadtName());
            }
            ywlx=joiner.toString();
        }
        //行业
        String industry=request.getParameter("industry");
        String hangye="";
        if(StringUtils.isNotBlank(industry)){
            StringJoiner joiner = new StringJoiner("、");
            String [] arr=industry.split(",");
            BaseDict base=new BaseDict();
            for(int i=0;i<arr.length;i++){
                base=baseDict("HY001",arr[i]);
                joiner.add(base.getBadtName());
            }
            hangye=joiner.toString();
        }
        //表头内容
        if(StringUtils.isBlank(start)||StringUtils.isBlank(xmgs)||StringUtils.isBlank(sheng)||StringUtils.isBlank(shi)) {
            content ="合同额对比统计表";
        }else{
            content = start+"至" + end + xmgs + "在" + sheng + shi+hangye + "行业的" + ywlx + "的合同额对比统计表";
        }

//        System.err.println(content);
        map.put("name",content);
        try {
            ExcelExportUtil.exportExcel(response,map,fileName,"78004");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public List<Map> selectContrastExce(HttpServletRequest request){
        List<Map> maps=new ArrayList<>();
        Map map=new HashMap();
        //时间段
        String startTime=request.getParameter("startTime");
        String endTime=request.getParameter("endTime");
        //省份
        String province=request.getParameter("province");
        //市
        String city=request.getParameter("city");
        //业务类型
        String projectType=request.getParameter("projectType");
        //项目归属
        String company=request.getParameter("company");
        //行业
        String industry=request.getParameter("industry");
        //项目状态
        String status=request.getParameter("status");
        //   System.err.println("时间段:"+times+"省份:"+province+"市："+city+"业务类型："+projectType+"项目归属："+company+"行业:"+industry);

        map.put("province",province);
        map.put("city",city);
        map.put("industry",list(industry));
        map.put("status",status);
        //时间段
        map.put("start",startTime);
        map.put("end",endTime);
        //先循环公司查询，在循环业务类型分别查询同一个公司加一起
        List<String> companys=list(company);

        for(int i=0;i<companys.size();i++){
            Map map1=new HashMap();
            BaseCompanyOwner baseCompany= baseCompanyOwnerService.selectByPrimaryKey(companys.get(i));
            if(StringUtils.isNotBlank(projectType)) {
                String[] arr = projectType.split(",");
                for (int j = 0; j < arr.length; j++) {
                    BaseDict base=baseDict("BT001",arr[j]);
                    Double amount=0.0;
                    if("001".equals(arr[j])){
                        map.put("company",companys.get(i));
                        SupervisorProjectDTO Jl=supervisorProjectMapper.selectAmountContrast(map);
                        if(Jl!=null&&!"".equals(Jl)){
                            amount=Double.parseDouble(Jl.getHtMoney());
                        }
                    }else if("002".equals(arr[j])){

                    }else if("003".equals(arr[j])){
                        //查询检测

                    }else if("100".equals(arr[j])){
                        //查询其他

                    }
                    map1.put(base.getBadtName(),amount);
                }

            }
            map1.put("company",baseCompany.getBcName());
            maps.add(map1);
        }
        return maps;
    }
    /**
     * 根据条件查询项目数量
     * @return
     */
    @RequestMapping(value="selectSigning")
    @ResponseBody
    public Map selectSigning(HttpServletRequest request,Model model){
        Map json=new HashMap();
        Map map=new HashMap();
        //时间段
        String startTime=request.getParameter("startTime");
        String endTime=request.getParameter("endTime");
        //省份
        String province=request.getParameter("province");
        //市
        String city=request.getParameter("city");
        //业务类型
        String projectType=request.getParameter("projectType");
        //项目归属
        String company=request.getParameter("company");
        //行业
        String industry=request.getParameter("industry");
//        System.err.println("时间段:"+times+"省份:"+province+"市："+city+"业务类型："+projectType+"项目归属："+company+"行业:"+industry);
        map.put("province",province);
        map.put("city",city);
        map.put("company",list(company));
        map.put("industry",list(industry));
        //时间段
        map.put("start",startTime);
        map.put("end",endTime);
//        System.err.println("当前时间："+DateUtil.getCurrentDateTimeString()+"加完的时间"+sdf.format(calendar.getTime()));

        int[] numbers=null;
//        String names="";
        StringJoiner names = new StringJoiner(",");
        if(StringUtils.isNotBlank(projectType)){
            String[] arr = projectType.split(",");
            numbers=new int[arr.length];
            for (int i=0;i<arr.length;i++){
                int number=0;
                map.put("projectType",arr[i]);
                map.put("status","004");
                if("001".equals(arr[i])){
                    //查询监理
                    map.put("type","001");
                    number=supervisorProjectMapper.selectSigning(map);
                    numbers[i]=number;
                    names.add("监理");
                }else if("002".equals(arr[i])){
                    //查询咨询
                    map.put("type","002");
                    number=zxProjectMapper.selectSigning(map);
                    numbers[i]=number;
                    names.add("咨询");
                }else if("003".equals(arr[i])){
                    //查询检测
                    map.put("type","003");
                    number=jcProjectMapper.selectSigning(map);
                    numbers[i]=number;
                    names.add("检测");
                }else if("100".equals(arr[i])){
                    //查询其他
                    map.put("type","100");
                    number=supervisorProjectMapper.selectSigning(map);
                    numbers[i]=number;
                    names.add("其他");
                }

            }
        }

        json.put("numbers",numbers);
        json.put("names",names.toString());
        return json;
    }

    /**
     * 项目进度查询
     * @param request
     * @return
     */
    @ResponseBody
    @GetMapping(value = "project")
    public Map project(HttpServletRequest request) {
        SupervisorProjectDTO spd=new SupervisorProjectDTO();
        Map re = new HashMap();
        Map map =new HashMap();
        //时间段
        String startTime=request.getParameter("startTime");
        String endTime=request.getParameter("endTime");
        //省份
        String province=request.getParameter("province");
        //市
        String city=request.getParameter("city");
        //业务类型
        String projectType=request.getParameter("projectType");
        //项目归属
        String company=request.getParameter("company");
        //行业
        String industry=request.getParameter("industry");
        //行业
        String projectNum=request.getParameter("projectNum");
//        System.err.println("时间段:"+times+"省份:"+province+"市："+city+"业务类型："+projectType+"项目归属："+company+"行业:"+industry);
        map.put("province",province);
        map.put("city",city);
        map.put("company",list(company));
        map.put("industry",list(industry));
        map.put("projectNum",Integer.parseInt(projectNum));
        //时间段
        map.put("start",startTime);
        map.put("end",endTime);
        StringJoiner name=new StringJoiner(",");
        StringJoiner num=new StringJoiner(",");
        if("001".equals(projectType)){
            List<SupervisorProjectDTO> list= supervisorProjectMapper.selectSupervisorList(map);
            if(list!=null && list.size()>0){
                for(SupervisorProjectDTO dto:list) {
                    name.add(dto.getProjectName());
                    num.add(dto.getProgress());
                }
            }
        }else if("002".equals(projectType)){
            List<ZxProjectDTO> list= zxProjectMapper.selectSupervisorList(map);
            if(list!=null && list.size()>0){
                for(ZxProjectDTO dto:list) {
                    name.add(dto.getProjectName());
                    num.add(dto.getProgress());
                }
            }
        }else if("003".equals(projectType)){
            List<JcProjectDTO> list= jcProjectMapper.selectSupervisorList(map);
            if(list!=null && list.size()>0){
                for(JcProjectDTO dto:list) {
                    name.add(dto.getProjectName());
                    num.add(dto.getProgress());
                }
            }
        }
        re.put("name",name.toString());
        re.put("num",num.toString());
        return re;
    }

    /**
     * 人员情况模块统计
     * @param request
     * @return
     */
    @RequestMapping("situation")
    @ResponseBody
    public Map situation(HttpServletRequest request){
        ReType re = new ReType();
        Map map=new HashMap();
        Map map1=new HashMap();
        String type=request.getParameter("type");
        String states=request.getParameter("states");
        String gxType=request.getParameter("gxType");
        //筛选条件 000是全部人 001是正中内部系统管理员代为注册 003是登录页面注册
        if(!"000".equals(states)){
            map.put("states",states);
        }
        //类型 全部 个人：001 组织：002
        List<SysUserDTO> userDw =new ArrayList<>();
        List<SysUserDTO> userXb=new ArrayList<>();
        List<SysUserDTO> userXl=new ArrayList<>();
        List<SysUserDTO> userNl=new ArrayList<>();
        if ("gr".equals(type)) {
            map.put("personType","001");
            //统计性别
            map.put("xb","xb");
            userXb=sysUserMapper.selectUserStats(map);
            map.remove("xb");
            map1.put("statsXb",userXb);
            //统计学历
            map.put("xl","xl");
            userXl=sysUserMapper.selectUserStats(map);
            map.remove("xl");
            map1.put("statsxl",userXl);
            //统计年龄
            map.put("nl","nl");
            userNl=sysUserMapper.selectUserStats(map);
            map.remove("nl");
            map1.put("statsnl",userNl);
        }else if("zz".equals(type)){
            map.put("personType","002");
            //组织中的类型
            map.put("gxType",gxType);
            //判断 查询单位性质
            map.put("dwxz", "dwxz");
            userDw = sysUserMapper.selectUserStats(map);
            map.remove("dwxz");
            map1.put("statsDw",userDw);
        }
        //判断 查询人员所在地的
        map.put("szd","szd");
        //统计所在地
        List<SysUserDTO> userSzd=sysUserMapper.selectUserStats(map);
        map.remove("szd");
        //判断 查询业务类型
        map.put("ywlx","ywlx");
        //统计业务类型
        List<SysUserDTO> userYw=sysUserMapper.selectUserStats(map);
        map.remove("ywlx");

        map1.put("statsSzd",userSzd);
        map1.put("statsYw",userYw);

        return map1;
    }

    /**
     * 查询公司合同额模块
     * @param request
     * @return
     */
    @RequestMapping("amount")
    @ResponseBody
    public Map amount(HttpServletRequest request)throws Exception{
        Map maps=new HashMap();
        Map map=new HashMap();
        //时间段
        String startTime=request.getParameter("startTime");
        String endTime=request.getParameter("endTime");
        //省份
        String province=request.getParameter("province");
        //市
        String city=request.getParameter("city");
        //业务类型
        String projectType=request.getParameter("projectType");
        //项目归属
        String company=request.getParameter("company");
        //行业
        String industry=request.getParameter("industry");
        //项目状态
        String status=request.getParameter("status");
        //   System.err.println("时间段:"+times+"省份:"+province+"市："+city+"业务类型："+projectType+"项目归属："+company+"行业:"+industry);
        map.put("province",province);
        map.put("city",city);
        map.put("company",list(company));
        map.put("industry",list(industry));
        map.put("status",status);
        //时间段
        map.put("start",startTime);
        map.put("end",endTime);
        List<String> timeList=getMonthBetween(startTime,endTime);
        String[] jlnumbers=null;
        String[] zxnumbers=null;
        String[] jcnumbers=null;
        String[] qtnumbers=null;
        StringJoiner name=new StringJoiner(",");
        if(StringUtils.isNotBlank(projectType)) {
            String[] arr = projectType.split(",");
            for (int i = 0; i < arr.length; i++) {
                if("001".equals(arr[i])){
                    //查询监理
                    if(timeList!=null&&timeList.size()>0) {
                        jlnumbers=new String[timeList.size()];
                        for (int j = 0; j < timeList.size(); j++) {
                            map.put("time",timeList.get(j));
                            List<SupervisorProjectDTO> listJl=supervisorProjectMapper.selectAmounts(map);
                            jlnumbers[j]=listJl.get(0).getHtMoney();
                        }
                    }
                    name.add("监理");
                }else if("002".equals(arr[i])){
                    //查询咨询
                    if(timeList!=null&&timeList.size()>0) {
                        zxnumbers=new String[timeList.size()];
                        for (int j = 0; j < timeList.size(); j++) {
                            map.put("time",timeList.get(j));
                            List<ZxProjectDTO> listZx=zxProjectMapper.selectAmounts(map);
                            zxnumbers[j]=listZx.get(0).getHtMoney();
                        }
                    }
                    name.add("咨询");
                }else if("003".equals(arr[i])){
                    //查询检测
                    if(timeList!=null&&timeList.size()>0) {
                        jcnumbers=new String[timeList.size()];
                        for (int j = 0; j < timeList.size(); j++) {
                            map.put("time",timeList.get(j));
                            List<JcProjectDTO> listJc=jcProjectMapper.selectAmounts(map);
                            jcnumbers[j]=listJc.get(0).getHtMoney();
                        }
                    }
                    name.add("检测");
                }else if("100".equals(arr[i])){
                    //查询其他

                    name.add("其他");
                }
            }
            maps.put("jlnumbers",jlnumbers);
            maps.put("zxnumbers",zxnumbers);
            maps.put("jcnumbers",jcnumbers);
            maps.put("qtnumbers",qtnumbers);
        }
        maps.put("time",timeList);
        maps.put("names",name.toString());
        return maps;
    }

    /**
     * 查询总部合同额模块
     * @param request
     * @return
     */
    @RequestMapping("headquarters/amounts")
    @ResponseBody
    public Map headquartersAmount(HttpServletRequest request)throws Exception{
        Map maps=new HashMap();
        Map map=new HashMap();
        //时间段
        String startTime=request.getParameter("startTime");
        String endTime=request.getParameter("endTime");
        //省份
        String province=request.getParameter("province");
        //市
        String city=request.getParameter("city");
        //业务类型
        String projectType=request.getParameter("projectType");
        //项目归属
        String company=request.getParameter("company");
        //行业
        String industry=request.getParameter("industry");
        //项目状态
        String status=request.getParameter("status");
        //   System.err.println("时间段:"+times+"省份:"+province+"市："+city+"业务类型："+projectType+"项目归属："+company+"行业:"+industry);
        map.put("province",province);
        map.put("city",city);
        map.put("company",company);
        map.put("industry",list(industry));
        map.put("status",status);
        //时间段
        map.put("start",startTime);
        map.put("end",endTime);
        StringJoiner name=new StringJoiner(",");
        String[] amounts=null;
        if(StringUtils.isNotBlank(projectType)) {
            String[] arr = projectType.split(",");
            amounts= new String[arr.length];
            for (int i = 0; i < arr.length; i++) {
                String amount="0";
                BaseDict baseDict=baseDict("BT001",arr[i]);
                if("001".equals(arr[i])){
                    //查询监理
                    SupervisorProjectDTO listJl=supervisorProjectMapper.selectHeadquartersAmount(map);
                    if(listJl!=null&&!"".equals(listJl)){
                        amount=listJl.getHtMoney();
                    }
                    amounts[i]=amount;
                }else if("002".equals(arr[i])){
                    //查询咨询
                    ZxProjectDTO listZx=zxProjectMapper.selectHeadquartersAmount(map);
                    if(listZx!=null&&!"".equals(listZx)){
                        amount=listZx.getHtMoney();
                    }
                    amounts[i]=amount;
                }else if("003".equals(arr[i])){
                    //查询检测
                    JcProjectDTO listJc=jcProjectMapper.selectHeadquartersAmount(map);
                    if(listJc!=null&&!"".equals(listJc)){
                        amount=listJc.getHtMoney();
                    }
                    amounts[i]=amount;
                }else if("100".equals(arr[i])){
                    //查询其他
                    amounts[i]=amount;
                }
                name.add(baseDict.getBadtName());
            }

        }
        maps.put("amount",amounts);
        maps.put("names",name.toString());
        return maps;
    }

    /**
     * 查询合同额对比模块
     * @param request
     * @return
     */
    @RequestMapping("contrast")
    @ResponseBody
    public Map contrast(HttpServletRequest request)throws Exception{
        Map maps=new HashMap();
        Map map=new HashMap();
        //时间段
        String startTime=request.getParameter("startTime");
        String endTime=request.getParameter("endTime");
        //省份
        String province=request.getParameter("province");
        //市
        String city=request.getParameter("city");
        //业务类型
        String projectType=request.getParameter("projectType");
        //项目归属
        String company=request.getParameter("company");
        //行业
        String industry=request.getParameter("industry");
        //项目状态
        String status=request.getParameter("status");
        //   System.err.println("时间段:"+times+"省份:"+province+"市："+city+"业务类型："+projectType+"项目归属："+company+"行业:"+industry);

        map.put("province",province);
        map.put("city",city);
        map.put("industry",list(industry));
        map.put("status",status);
        //时间段
        map.put("start",startTime);
        map.put("end",endTime);
        //先循环公司查询，在循环业务类型分别查询同一个公司加一起
        List<String> companys=list(company);
        String num="";
        String name="";
        for(int i=0;i<companys.size();i++){
            BaseCompanyOwner baseCompany= baseCompanyOwnerService.selectByPrimaryKey(companys.get(i));
            name=baseCompany.getBcName()+","+name;
            if(StringUtils.isNotBlank(projectType)) {
                Double amount=0.0;
                String[] arr = projectType.split(",");
                for (int j = 0; j < arr.length; j++) {
                    if("001".equals(arr[j])){
                        map.put("company",companys.get(i));
                        SupervisorProjectDTO Jl=supervisorProjectMapper.selectAmountContrast(map);
                        if(Jl!=null&&!"".equals(Jl)){
                            amount+=Double.parseDouble(Jl.getHtMoney());
                        }
                    }else if("002".equals(arr[j])){
                        //查询咨询
                        map.put("company",companys.get(i));
                        ZxProjectDTO ZX=zxProjectMapper.selectAmountContrast(map);
                        if(ZX!=null&&!"".equals(ZX)){
                            amount+=Double.parseDouble(ZX.getHtMoney());
                        }
                    }else if("003".equals(arr[j])){
                        //查询检测
                        map.put("company",companys.get(i));
                        JcProjectDTO JC=jcProjectMapper.selectAmountContrast(map);
                        if(JC!=null&&!"".equals(JC)){
                            amount+=Double.parseDouble(JC.getHtMoney());
                        }
                    }else if("100".equals(arr[j])){
                        //查询其他
                    }
                }
                num=String.format("%.2f",amount)+","+num;

            }
        }
        num=num.substring(0, num.length() -1);
        name=name.substring(0, name.length() -1);
        maps.put("amount",num);
        maps.put("names",name);
        return maps;
    }

    /**
     * 项目分布
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("distributions")
    public ReType distributions(HttpServletRequest request){
        ReType reType=new ReType();
        Map map=new HashMap();
        //时间段
        String startTime=request.getParameter("startTime");
        String endTime=request.getParameter("endTime");
        //业务类型
        String projectType=request.getParameter("projectType");
        //项目归属
        String company=request.getParameter("company");
        //项目状态
        String status=request.getParameter("status");

        map.put("status",status);
        map.put("company",list(company));

        //时间段
        map.put("start",startTime);
        map.put("end",endTime);
//        Calendar calendar = Calendar.getInstance();
//        calendar.setTime(DateUtil.getCurrentDateTime());
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        if (StringUtils.isNotBlank(times)) {
//            BaseDict base=baseDict("SJD001",times);
//            if("月".equals(base.getBadtLevel2())){
//                calendar.add(Calendar.MONTH, -(Integer.parseInt(base.getBadtLevel1())));
//            }else if("年".equals(base.getBadtLevel2())){
//                calendar.add(Calendar.YEAR, -(Integer.parseInt(base.getBadtLevel1())));
//            }
//            map.put("start",sdf.format(calendar.getTime()));
//            map.put("end",DateUtil.getCurrentDateTimeString());
//        }
//        查询所有地区
        List<SysRegion> provincelist = sysRegionService.selectListByLevelId("1");
        List<Map> list=new ArrayList<>();
        for(int i=0;i<provincelist.size();i++){
            Map map1=new HashMap();
            map1.put("name",provincelist.get(i).getName());
            String[] arr=projectType.split(",");
//            int num=0;
//            double money=0.0;
            BigDecimal big=new BigDecimal("0");
            BigDecimal money=new BigDecimal("0.00");
            String jianli="";
            String zixun="";
            String jiance="";
//            查询不同业务类型对应的项目个数和合同金额
            map.put("province",provincelist.get(i).getCode());
            //查询项目所在的城市
            List<SupervisorProjectDTO> allCity=supervisorProjectMapper.selectAllCity(map);
            for(int j=0;j<arr.length;j++){
                if("001".equals(arr[j])){
                    SupervisorProjectDTO spd=supervisorProjectMapper.selectDistribution(map);
                    big=big.add(new BigDecimal(spd.getNum()));
                    money=money.add(new BigDecimal(spd.getHtMoney()));
                    map1.put("jl",spd);
//                    //标注该城市是监理项目 取第一个城市
//                    if(StringUtils.isNotBlank(spd.getProvince())){
//                        List<SysRegion> sysRegion =region(provincelist.get(i).getId());
//                        if(sysRegion!=null&&sysRegion.size()>=2){
//                            jianli=sysRegion.get(2).getName();
//                        }
//                    }
                }else if("002".equals(arr[j])){
                    ZxProjectDTO zxspd=zxProjectMapper.selectDistribution(map);
                    big=big.add(new BigDecimal(zxspd.getNum()));
                    money=money.add(new BigDecimal(zxspd.getHtMoney()));
                    map1.put("zx",zxspd);
//                    //标注该城市是咨询项目 取第二个城市
//                    if(StringUtils.isNotBlank(zxspd.getProvince())){
//                        List<SysRegion> sysRegion =region(provincelist.get(i).getId());
//                        if(sysRegion!=null&&sysRegion.size()>=3){
//                            zixun=sysRegion.get(3).getName();
//                        }
//                    }
                }else if("003".equals(arr[j])){
                    JcProjectDTO jcspd=jcProjectMapper.selectDistribution(map);
                    big=big.add(new BigDecimal(jcspd.getNum()));
                    money=money.add(new BigDecimal(jcspd.getHtMoney()));
                    map1.put("jcs",jcspd);
//                    //标注该城市是咨询项目 取第三个城市
//                    if(StringUtils.isNotBlank(jcspd.getProvince())){
//                        List<SysRegion> sysRegion =region(provincelist.get(i).getId());
//                        if(sysRegion!=null&&sysRegion.size()>=4){
//                            jiance=sysRegion.get(4).getName();
//                        }
//                    }
                }else if("004".equals(arr[j])){
                    map1.put("qt",null);
                }
            }
            //各个地区的项目总数和总金额
//            map1.put("jianli",jianli);
//            map1.put("zixun",zixun);
//            map1.put("jiance",jiance);
            map1.put("allCity",allCity);
            map1.put("num",big.toString());
            map1.put("money",money.toString());
            list.add(map1);
        }


        //查询分公司所在的地区
        StringJoiner region=new StringJoiner(",");
        StringJoiner values=new StringJoiner(",");
        List<BaseCompanyOwner> listCom=baseCompanyOwnerService.selectAll();
        for(BaseCompanyOwner com:listCom){
            if(StringUtils.isNotBlank(com.getRegion())) {
                region.add(com.getRegion());
                values.add("200");
            }
        }
        if(list!=null&&list.size()>0){
            list.get(0).put("region",region.toString());
            list.get(0).put("values",values.toString());
        }
        reType.setData(list);
        return reType;
    }

    //根据id查询城市数据
    public List<SysRegion> region(Long id){
        //城市
        SysRegion sysRegion =new SysRegion();
        sysRegion.setParentId(id);
        return sysRegionService.select(sysRegion);
    }
    //传入两个日期 获取之间的时间年月
    public static List<String> getMonthBetween(String minDate, String maxDate) throws Exception{
        ArrayList<String> result = new ArrayList<String>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");// 格式化为年月
        Calendar min = Calendar.getInstance();
        Calendar max = Calendar.getInstance();
        min.setTime(sdf.parse(minDate));
        min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1);// 设置年月日，最少3个参数
        max.setTime(sdf.parse(maxDate));
        max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2);
        Calendar curr = min;
        while (curr.before(max))
        {
            result.add(sdf.format(curr.getTime()));
            curr.add(Calendar.MONTH, 1);
        }
        return result;
    }

    //逗号分割返回List
    public List<String> list(String name){
        List<String> list = new ArrayList<>();
        if(StringUtils.isNotBlank(name)) {
            String[] arr = name.split(",");
            for (int i = 0; i < arr.length; i++) {
                list.add(arr[i]);
            }
        }
        return list;
    }
    //根据类型查询字典
    public List<BaseDict> base(DictTypes type){
        return DictUtil.getDictByType(type);
    }
    //传入字典类型编号，字典编号 查询字典
    public BaseDict baseDict(String type,String code){
        BaseDict base=new BaseDict();
        base.setBadtTypecode(type);
        base.setBadtCode(code);
        BaseDict baseDict =new BaseDict();
        if(StringUtils.isNotBlank(code)) {
            baseDict = baseDictService.selectOne(base);
        }
        return baseDict;
    }

}
